package xyz.ddlnt.user.usr.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.commonutil.util.HttpUtils;
import xyz.ddlnt.model.dto.NoteAddDTO;
import xyz.ddlnt.model.dto.NoteDTO;
import xyz.ddlnt.model.dto.NoteDirDTO;
import xyz.ddlnt.model.vo.NoteContentVO;
import xyz.ddlnt.model.vo.NoteVO;
import xyz.ddlnt.serviceusrclient.client.NoteFeignClient;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/7 15:08
 */
@Slf4j
@Tag(name = "笔记管理接口")
@RequestMapping("/note")
@RestController
public class NoteController {

    @Resource
    private NoteFeignClient noteFeignClient;

    @Operation(summary = "添加笔记")
    @PostMapping("/addNote")
    Result<NoteVO> addNote(@RequestBody NoteAddDTO noteAddDTO, HttpServletRequest request) {
        noteAddDTO.setUserId(HttpUtils.getId(request));
        return noteFeignClient.addNote(noteAddDTO);
    }

    @Operation(summary = "删除笔记")
    @DeleteMapping("/deleteNote/{id}")
    Result<Boolean> deleteNote(@PathVariable Long id) {
        return noteFeignClient.deleteNote(id);
    }

    @Operation(summary = "更新笔记标题")
    @PutMapping("/updateNoteTitle")
    Result<Boolean> updateNoteTitle(@RequestBody NoteDTO noteDTO) {
        return noteFeignClient.updateNoteTitle(noteDTO);
    }

    @Operation(summary = "更新笔记前节点子集")
    @PutMapping("/updateNoteChildNodes")
    Result<Boolean> updateNoteChildNodes(@RequestBody NoteDirDTO noteDirDTO) {
        return noteFeignClient.updateNoteChildNodes(noteDirDTO);
    }

    @Operation(summary = "更新笔记内容")
    @PutMapping("/updateNote")
    Result<Boolean> updateNote(@RequestBody NoteDTO noteDTO) {
        return noteFeignClient.updateNote(noteDTO);
    }

    @Operation(summary = "获取笔记目录")
    @PostMapping("/getNoteDir")
    Result<List<NoteVO>> getNote(@RequestBody NoteDirDTO noteDirDTO, HttpServletRequest request) {
        noteDirDTO.setUserId(HttpUtils.getId(request));
        return noteFeignClient.getNote(noteDirDTO);
    }

    @Operation(summary = "获取笔记内容")
    @GetMapping("/getNoteContent/{id}")
    Result<NoteContentVO> getNoteContent(@PathVariable Long id) {
        return noteFeignClient.getNoteContent(id);
    }
}
